package com.aizhixin.lab.project.course.controller;

import com.aizhixin.lab.account.dto.AccountDTO;
import com.aizhixin.lab.account.service.AccountService;
import com.aizhixin.lab.common.core.ApiReturnConstants;
import com.aizhixin.lab.common.utils.TokenUtil;
import com.aizhixin.lab.project.course.domain.AddTeacherDomain;
import com.aizhixin.lab.project.course.service.StudentProjectService;
import com.aizhixin.lab.project.course.service.TeacherProjectService;
import com.aizhixin.lab.project.course.vo.*;
import com.aizhixin.lab.project.template.domain.ProjectDomain;
import com.aizhixin.lab.project.template.domain.WorkOrderDomain;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/api/v1/teacher/projectTask")
@RestController
@Api(value = "学生端项目模块", tags = "学生端项目模块")
public class StudentProjectController {
    @Autowired
    private StudentProjectService projectService;
    @Autowired
    private AccountService accountService;


    @RequestMapping(value = "/findTaskProgress", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "项目组总体数据-任务进度", httpMethod = "GET", notes = "项目组总体数据-任务进度")
    public ResponseEntity<?> findTaskProgress(@RequestHeader("Authorization") String token,@ApiParam(value = "项目ID") @RequestParam String projectId
            ,@ApiParam(value = "小组ID") @RequestParam String groupId
    ) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        try{
            ProjectTaskProgressVo publish = projectService.findTaskProgress(projectId,groupId);
            result.put(ApiReturnConstants.SUCCESS, true);
            result.put(ApiReturnConstants.DATA,publish);
        }catch (Exception e){
            result.put(ApiReturnConstants.SUCCESS, false);
            result.put(ApiReturnConstants.ERROR,e.getMessage());
        }
        return  new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findMemberContribute", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "项目组总体数据-成员贡献度--大饼图", httpMethod = "GET", notes = "项目组总体数据-成员贡献度--大饼图")
    public ResponseEntity<?> findMemberContribute(@RequestHeader("Authorization") String token,@ApiParam(value = "项目ID") @RequestParam String projectId
            ,@ApiParam(value = "小组ID") @RequestParam String groupId
    ) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        try{
            List<ProjectMemberContributeVo> publish = projectService.findMemberContribute(projectId,groupId);
            result.put(ApiReturnConstants.SUCCESS, true);
            result.put(ApiReturnConstants.DATA,publish);
        }catch (Exception e){
            result.put(ApiReturnConstants.SUCCESS, false);
            result.put(ApiReturnConstants.ERROR,e.getMessage());
        }
        return  new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findMemberContributeChart", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "项目组总体数据-成员贡献度--柱形图", httpMethod = "GET", notes = "项目组总体数据-成员贡献度--柱形图")
    public ResponseEntity<?> findMemberContributeChart(@RequestHeader("Authorization") String token,@ApiParam(value = "项目ID") @RequestParam String projectId
            ,@ApiParam(value = "小组ID") @RequestParam String groupId
    ) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        try{
            List publish = projectService.findMemberContributeChart(projectId,groupId);
            result.put(ApiReturnConstants.SUCCESS, true);
            result.put(ApiReturnConstants.DATA,publish);
        }catch (Exception e){
            result.put(ApiReturnConstants.SUCCESS, false);
            result.put(ApiReturnConstants.ERROR,e.getMessage());
        }
        return  new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findReleaseTask", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "项目组总体数据-发布任务时间点折线图", httpMethod = "GET", notes = "项目组总体数据-发布任务时间点折线图")
    public ResponseEntity<?> findReleaseTask(@RequestHeader("Authorization") String token,@ApiParam(value = "项目ID") @RequestParam String projectId
            ,@ApiParam(value = "小组ID") @RequestParam String groupId
    ) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
            Map publish = projectService.findReleaseTask(projectId,groupId);
            result.put(ApiReturnConstants.SUCCESS, true);
            result.put(ApiReturnConstants.DATA,publish);
        
        return  new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findTaskCondition", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "项目统计-个人任务完成情况--表格加大饼", httpMethod = "GET", notes = "项目统计-个人任务完成情况--表格加大饼")
    public ResponseEntity<?> findTaskCondition(@RequestHeader("Authorization") String token,@ApiParam(value = "项目ID") @RequestParam String projectId
            ,@ApiParam(value = "小组ID") @RequestParam String groupId
    ) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        try{
            List<ProjectTaskConditionVo> publish = projectService.findTaskCondition(projectId,groupId,account.getId());
            result.put(ApiReturnConstants.SUCCESS, true);
            result.put(ApiReturnConstants.DATA,publish);
        }catch (Exception e){
            result.put(ApiReturnConstants.SUCCESS, false);
            result.put(ApiReturnConstants.ERROR,e.getMessage());
        }
        return  new ResponseEntity(result, HttpStatus.OK);
    }


    @RequestMapping(value = "/findTaskScore", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "项目统计-个人任务得分统计", httpMethod = "GET", notes = "项目统计-个人任务得分统计")
    public ResponseEntity<?> findTaskScore(@RequestHeader("Authorization") String token,@ApiParam(value = "项目ID") @RequestParam String projectId
            ,@ApiParam(value = "小组ID") @RequestParam String groupId
    ) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        try{
            List publish = projectService.findTaskScore(projectId,groupId,account.getId());
            result.put(ApiReturnConstants.SUCCESS, true);
            result.put(ApiReturnConstants.DATA,publish);
        }catch (Exception e){
            result.put(ApiReturnConstants.SUCCESS, false);
            result.put(ApiReturnConstants.ERROR,e.getMessage());
        }
        return  new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findGroupTask", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "项目统计-任务组完成任务情况", httpMethod = "GET", notes = "项目统计-任务组完成任务情况")
    public ResponseEntity<?> findGroupTask(@RequestHeader("Authorization") String token,@ApiParam(value = "项目ID") @RequestParam String projectId
            ,@ApiParam(value = "小组ID") @RequestParam String groupId
    ) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        try{
            List publish = projectService.findGroupTask(projectId,groupId,account.getId());
            result.put(ApiReturnConstants.SUCCESS, true);
            result.put(ApiReturnConstants.DATA,publish);
        }catch (Exception e){
            result.put(ApiReturnConstants.SUCCESS, false);
            result.put(ApiReturnConstants.ERROR,e.getMessage());
        }
        return  new ResponseEntity(result, HttpStatus.OK);
    }


    @RequestMapping(value = "/findGroupTaskGraspKnowledge", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "项目统计-任务组每个人知识点技能点得分", httpMethod = "GET", notes = "项目统计-任务组每个人知识点技能点得分")
    public ResponseEntity<?> findGroupTaskGraspKnowledge(@RequestHeader("Authorization") String token,@ApiParam(value = "项目ID") @RequestParam String projectId
            ,@ApiParam(value = "小组ID") @RequestParam String groupId
    ) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }

        List<TaskGroupSkillsknowledgeScoreVo> publish = projectService.findGroupTaskGraspKnowledge(projectId,groupId);
        result.put(ApiReturnConstants.SUCCESS, true);
        result.put(ApiReturnConstants.DATA,publish);

        return  new ResponseEntity(result, HttpStatus.OK);
    }


    @RequestMapping(value = "/findGraspKnowledge", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "项目统计-个人知识点技能点情况", httpMethod = "GET", notes = "项目统计-个人知识点技能点情况")
    public ResponseEntity<?> findGraspKnowledge(@RequestHeader("Authorization") String token,@ApiParam(value = "项目ID") @RequestParam String projectId
            ,@ApiParam(value = "小组ID") @RequestParam String groupId
    ) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        try{
            Map publish = projectService.findGraspKnowledge(projectId,groupId,account.getId());
            result.put(ApiReturnConstants.SUCCESS, true);
            result.put(ApiReturnConstants.DATA,publish);
        }catch (Exception e){
            result.put(ApiReturnConstants.SUCCESS, false);
            result.put(ApiReturnConstants.ERROR,e.getMessage());
        }
        return  new ResponseEntity(result, HttpStatus.OK);
    }


    @RequestMapping(value = "/findProjectCurriculum", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "项目相关课程与职位", httpMethod = "GET", notes = "项目相关课程与职位")
    public ResponseEntity<?> findProjectCurriculum(@RequestHeader("Authorization") String token,@ApiParam(value = "项目ID") @RequestParam String projectId) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        try{
            Map publish = projectService.findProjectCurriculum(projectId);
            result.put(ApiReturnConstants.SUCCESS, true);
            result.put(ApiReturnConstants.DATA,publish);
        }catch (Exception e){
            result.put(ApiReturnConstants.SUCCESS, false);
            result.put(ApiReturnConstants.ERROR,e.getMessage());
        }
        return  new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findProjectInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "当前项目基本信息", httpMethod = "GET", notes = "当前项目基本信息")
    public ResponseEntity<?> findProjectInfo(@RequestHeader("Authorization") String token,@ApiParam(value = "项目ID") @RequestParam(name = "projectId") String projectId) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }

            Map publish = projectService.findProjectInfo(projectId,account.getId());
            result.put(ApiReturnConstants.SUCCESS, true);
            result.put(ApiReturnConstants.DATA,publish);

        return  new ResponseEntity(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/findGroupTaskList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "学生端获取模块下的任务", httpMethod = "GET", notes = "学生端获取模块下的任务")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = StuTaskVo.class),})
    public ResponseEntity<?> findGroupTaskList(@RequestHeader("Authorization") String token,
                                               @ApiParam(value = "小组ID为空时查询我的任务,不为空时查询全部任务") @RequestParam String groupId,
                                               @ApiParam(value = "模块ID") @RequestParam String moduleId,
                                               @ApiParam(value = "任务状态") @RequestParam String taskStatus,
                                               @ApiParam(value = "pageNumber 起始页") @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
                                               @ApiParam(value = "pageSize 每页的限制数目") @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        AccountDTO account = accountService.getUserByToken(token);
        Map<String, Object> result = new HashMap<String, Object>();
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        result = projectService.stuTaskVoList(groupId, moduleId,account.getId(),taskStatus,pageSize,pageNumber);

        return  new ResponseEntity(result, HttpStatus.OK);
    }

}
